<?php

class Admin_CaiJiaGeController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
        $this->view->headScript()->appendFile($this->view->baseUrl().'/js/jquery-1.8.1.min.js');
        
    }

    public function indexAction()
    {
        // action body
    }
    
    public function addNewAction(){
        
        if($this->getRequest()->isPost()){
            $data=array();
            $name=$this->getRequest()->getParam('name');
            if(null!=$name){
                $data['name']=trim($name);
            }
            
            $urlSpell=$this->getRequest()->getParam('urlSpell');
            if(null!=$urlSpell){
                $data['url_spell']=trim($urlSpell);
            }
            $adapter = new Zend_File_Transfer_Adapter_Http();
            $month=(string)date('Ym',time());
    		$daytime=(string)date('dHi',time());
    		$path="./images/caijiage/".$month."/".$daytime;
    		if(!is_dir($path)){
    			mkdir($path,0777,true);
    		}
            $adapter->setDestination($path);
            if($adapter->isUploaded('icon')){
                $adapter->receive('icon');
                $data['icon']=DOMAIN_URL."/images/caijiage/".$month."/".$daytime."/".basename($adapter->getFileName('icon'));
            }
            $keyWords=$this->getRequest()->getParam('keyWords');
            if(null!=$keyWords){
                $data['key_words']=trim($keyWords);
            }
            
            $owner=$this->getRequest()->getParam('owner');
            if(null!=$owner){
                $data['owner']=trim($owner);
            }
            $textDesc=$this->getRequest()->getParam('textDesc');
            if(null!=$textDesc){
                $data['text_desc']=trim($textDesc);
            }
            
            if($adapter->isUploaded('uploadImg')){
                $adapter->receive('uploadImg');
                $data['img']=DOMAIN_URL."/images/caijiage/".$month."/".$daytime."/".basename($adapter->getFileName('uploadImg'));
            }else{
                $linkImg=$this->getRequest()->getParam('linkImg');
                if(null!=$linkImg){
                    $data['img']=trim($linkImg);
                }
            }
            
            $size=$this->getRequest()->getParam('size');
            if(null!=$size){
                $data['size']=trim($size);
            }
            $weight=$this->getRequest()->getParam('weight');
            if(null!=$weight){
                $data['weight']=trim($weight);
            }
            
            $price=$this->getRequest()->getParam('price');
            if(null!=$price){
                $data['price']=trim($price);
            }
    
            $date=$this->getRequest()->getParam('date');
            if(null!=$date){
                $data['date']=trim($date);
            }
            
            $type=$this->getRequest()->getParam('type');
            if(null!=$type){
                $data['type']=trim($type);
            }
            
            $link=$this->getRequest()->getParam('link');
            if(null!=$link){
                $data['link']=trim($link);
            }
            $dbCaiJiaGe=new Application_Model_DbTable_CaiJiaGe();
            $dbCaiJiaGe->addNew($data);
        }
        
    }
    
    public function ajaxGetUrlSpellAction(){
        $this->_helper->layout()->disableLayout();
        $name=$this->getRequest()->getParam('name');
        $pinyin= new Txy_Util_PinYin();
        $spell=$pinyin->getPinYin(mb_convert_encoding($name,'gbk','utf-8'));
        echo $spell;
    }

}

